<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <!-- 常用的生命周期方法：
      1、mounted：发送ajax请求、启动定时器、订阅消息
      2、beforeDestroy:清除定时器、取消消息订阅

      Vue销毁之后，DOM事件依然有效
  -->
  <!-- 准备好一个容器-->
  <div id="app">
    num的值：{{num}} <br/>
    <button @click="add()">num加一</button>
    <button @click="des()">销毁</button>
  </div>
  <script src="vue.js"></script>
  <script>
    Vue.config.productionTip = false //阻止 vue 在启动时生成生产提示。
    //创建vue实例
    new Vue({
      el: '#app',
      data: {
        num: 1
      },
      methods: {
        add() {
          console.log('add');
          this.num++;
        },
        des() {
          console.log('des');
          this.$destroy();
        }
      },
      beforeCreate() {
        console.log('beforeCreate');
      },
      created() {
        console.log('created');
      },
      beforeMount() {
        console.log('beforeMount');
      },
      mounted() {
        console.log('mounted');
      },
      beforeDestroy() {
        console.log('beforeDestroy');
      },
      destroyed() {
        console.log('destroyed');
      },
      beforeUpdate() {
        console.log('beforeUpdate');
      },
      updated() {
        console.log('updated');
      },
    })
  </script>
</body>

</html>